In Docker, containers are removed using the docker rm command. A container must be stopped before it can be removed unless you force-remove it. You can remove single containers, multiple containers, or all stopped containers at once using various flags and commands.
A running container CANNOT be removed without the -f (force) flag
A stopped container CAN be removed with docker rm <container>
Removing a container does NOT remove its image
Removing a container DOES delete its writable layer and any data not in a volume
Container name or container ID can be used interchangeably in all commands
docker rm <name> — removes one or more specific containers by name or ID
docker rm -f <name> — force removes a running container without stopping it first
docker rm -v <name> — removes container and its anonymous volumes
docker container prune — removes ALL stopped containers in one command
docker system prune — removes stopped containers, unused networks, dangling images, build cache
docker system prune -a — also removes all unused images (not just dangling)
docker system prune --volumes — also removes all unused volumes (dangerous — data loss)
Always stop a container gracefully with docker stop before docker rm when possible
Use docker rm -f only when you do not care about graceful shutdown
Use --rm on docker run for ephemeral containers that should auto-cleanup on exit
docker rm -v removes anonymous volumes but NOT named volumes
docker container prune is the cleanest way to remove all stopped containers at once
Removing a container never removes its image — use docker rmi to remove images
Use docker system prune periodically in CI/CD pipelines to reclaim disk space